package gae.testjig.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class UITestStatus extends Composite {

	interface UITestStatusUiBinder extends UiBinder<Widget, UITestStatus> {}
	private static UITestStatusUiBinder uiBinder = GWT.create(UITestStatusUiBinder.class);

	@UiField Label lblInvocations;
	@UiField Label lblRetries;
	@UiField Label lblMismatches;
	
	public UITestStatus() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	public void setInvocations(int count) {
		lblInvocations.setText(""+count);
	}

	public int getInvocations() {
		String invocationsString = lblInvocations.getText();
		try {
			return Integer.parseInt(invocationsString);
		}
		catch (NumberFormatException e) {
			return 0;
		}
	}

	public void setRetries(int count) {
		lblRetries.setText(""+count);
	}

	public int getRetries() {
		String retriesString = lblRetries.getText();
		try {
			return Integer.parseInt(retriesString);
		}
		catch (NumberFormatException e) {
			return 0;
		}
	}
	
	public void setMismatches(int count) {
		lblMismatches.setText(""+count);
	}

	public int getMismatches() {
		String mismatchesString = lblMismatches.getText();
		try {
			return Integer.parseInt(mismatchesString);
		}
		catch (NumberFormatException e) {
			return 0;
		}
	}

	public void reset() {
		lblInvocations.setText("0");
		lblRetries.setText("0");
		lblMismatches.setText("0");
	}

}
